# Maintainer: Alexey Pavlov <Alexpux@gmail.com>
# Contributor: Paul Moore <p.f.moore@gmail.com>

_realname=bc
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.07.1
pkgrel=1
pkgdesc='bc is an arbitrary precision numeric processing language (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://www.gnu.org/software/bc/'
license=('GPL3')
options=('strip' '!libtool' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc" "ed")
depends=("${MINGW_PACKAGE_PREFIX}-readline")
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-use-rand-on-windows.patch"
        "0002-fix-fix-libmath_h.patch"
        "0003-use-binary-io.patch")
sha256sums=('62adfca89b0a1c0164c2cdca59ca210c1d44c3ffc46daf9931cf4942664cb02a'
            'd0203c9cbe9764ddb4ef50f5c2bda6f0b0483d01d2c5e8722be5826c28300f71'
            'c1c638e5387dd81ac210ed1bc68e4e09e23a18b0fd992ff03dbe5e1390ff3706'
            '1c796bb531b1d516e0170d4bd88ff8c6869d41132736eab27da4fcc9e6fdfad2')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0001-use-rand-on-windows.patch
  patch -p1 -i "${srcdir}"/0002-fix-fix-libmath_h.patch
  patch -p1 -i "${srcdir}"/0003-use-binary-io.patch
  autoreconf -fiv
}

build() {
  cd $srcdir/${_realname}-${pkgver}
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-readline

  make
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}
  make install DESTDIR="${pkgdir}"

  # Licenses
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/README" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/README"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
